import React, {Component} from 'react';
import {connect} from 'react-redux';
import {fetchNewsDetail, fetchNewsType} from '../../actions/newsAction';
import NavLink from '../NavLink';
import {log} from 'core-js/library/web/timers';
class NewsDetail extends Component {
    constructor() {
        super();
        this.state = {
            dataSource: ""
        };
    }
    componentWillMount() {
        var params = this.props.params.newsId
        this
            .props
            .fetchNewsDetail(params);
            const typeId=this.props.location.state.data;
            this
            .props
            .fetchNewsType(typeId);
    }
    render() {
        //获取新闻详情
        console.log(this.props)
        const {newsDetail,newsType} = this.props;
        // console.log(this.props)
        if (JSON.stringify(newsDetail) != "{}") {

            return (
                <div>
                    <ol className="breadcrumb">
                        <li>
                            <NavLink to='/news'>
                                全部新闻
                            </NavLink>
                        </li>
                        <li>
                        <NavLink to='/news'>
                          {newsType.title}
                        </NavLink>
                    </li>
                        <li className="active">当前新闻</li>
                    </ol>
                    <hr className="featurette-divider"/>

                    <div className="row featurette">
                        <div className="col-md-7">
                            <h2 className="featurette-heading">{newsDetail.title}</h2>
                            <div
                                className="lead"
                                dangerouslySetInnerHTML={{
                                __html: newsDetail.content
                            }}></div>
                        </div>
                        <div className="col-md-5">
                            <img
                                className="featurette-image img-responsive center-block"
                                src={`http://localhost:3000/${newsDetail.imgObject.filename}`}
                                alt="Generic placeholder image"/>
                        </div>
                    </div>
                    <hr className="featurette-divider"/>
                </div>
            )
        } else {
            return (
                <div>请求数据中......</div>
            )
        }

    }
}
const getValue = (state) => {
    return {newsDetail: state.newsReducer.newsDetail,
            newsType:state.newsReducer.newsType
    
    }
}
const newsDetailContext = connect(getValue, {fetchNewsDetail, fetchNewsType})(NewsDetail)
module.exports = newsDetailContext;